package com.example.mybatisplus.web.controller;

import ch.qos.logback.classic.net.server.HardenedLoggingEventInputStream;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.*;
import com.example.mybatisplus.model.dto.DormitoryAdminForm;
import com.example.mybatisplus.model.dto.StudentForm;
import com.example.mybatisplus.service.*;
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.QEncoderStream;
import jdk.nashorn.internal.scripts.JO;
import org.apache.tomcat.jni.Local;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;

import java.time.LocalDateTime;
import java.util.*;

import static java.lang.Math.max;
import static java.lang.Math.min;


/**
 *
 *  前端控制器
 *
 *
 * @author zzy
 * @since 2024-06-24
 * @version v1.0
 */
@Controller
@RequestMapping("/api/superAdmin")
public class SuperAdminController {

    private final Logger logger = LoggerFactory.getLogger( SuperAdminController.class );

    @Autowired
    private SuperAdminService superAdminService;
    @Autowired
    private AreaService areaService;
    @Autowired
    private BuildingService buildingService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private LeaderService leaderService;
    @Autowired
    private  KeeperService keeperService;
    @Autowired
    private  TeacherService teacherService;
    @Autowired
    private  DormitoryAdminService dormitoryAdminService;
    @Autowired
    private RoomService roomService;
    int roomNumPerFloor = 12;
    /**
    * 描述：根据Id 查询
    *
    */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public JsonResponse getById(@PathVariable("id") Long id)throws Exception {
        SuperAdmin  superAdmin =  superAdminService.getById(id);
        return JsonResponse.success(superAdmin);
    }

    /**
    * 描述：根据Id删除
    *
    */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public JsonResponse deleteById(@PathVariable("id") Long id) throws Exception {
        superAdminService.removeById(id);
        return JsonResponse.success(null);
    }


    /**
    * 描述：根据Id 更新
    *
    */
    @RequestMapping(value = "", method = RequestMethod.PUT)
    @ResponseBody
    public JsonResponse updateSuperAdmin(SuperAdmin  superAdmin) throws Exception {
        superAdminService.updateById(superAdmin);
        return JsonResponse.success(null);
    }


    /**
    * 描述:创建SuperAdmin
    *
    */
    @RequestMapping(value = "", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse create(SuperAdmin  superAdmin) throws Exception {
        superAdminService.save(superAdmin);
        return JsonResponse.success(null);
    }

    @PostMapping("/selectAreaByAreaname")
    @ResponseBody
    public JsonResponse selectAreaByAreaname(@RequestBody Dot dot){
        dot.setPageNo((dot.getPageNo()-1)*dot.getPageSize());
        List<Area> areaList =  areaService.selectAreaPageByName(dot);
        return JsonResponse.success(areaList, "Success.");
    }
    @PostMapping("/areaAdd")
    @ResponseBody
    public JsonResponse areaAdd(@RequestBody Map<String, Object> params){

        boolean b = areaService.areaAdd(params);
        if(b)return JsonResponse.success(b, "Area add success.");
        else return JsonResponse.failure("The area has been existed.");
    }
    @PostMapping("/areaAll")
    @ResponseBody
    public JsonResponse areaAll(@RequestBody Dot dot){

        Page<Area> page = new Page<Area>(dot.getPageNo(), dot.getPageSize());
        IPage<Area> Area = areaService.page(page, new QueryWrapper<Area>());
        int count = areaService.count();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("size", count);
        return JsonResponse.success(page.getRecords()).setOtherData(map);
    }
    @PostMapping("/buildingAll")
    @ResponseBody
    public JsonResponse buildingAll(@RequestBody Dot dot){
        Page<Building> page = new Page<Building>(dot.getPageNo(), dot.getPageSize());
        IPage<Building> iPage = buildingService.page(page, new QueryWrapper<Building>());
        int count = buildingService.count();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("size", count);
        return JsonResponse.success(page.getRecords()).setOtherData(map);
    }

    @PostMapping("/roomAll")
    @ResponseBody
    public JsonResponse roomAll(@RequestBody Dot dot){
        Page<Room> page = new Page<Room>(dot.getPageNo(), dot.getPageSize());
        IPage<Room> iPage = roomService.page(page, new QueryWrapper<Room>());
        int count = leaderService.count();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("size", count);
        return JsonResponse.success(page.getRecords()).setOtherData(map);
    }

    @PostMapping("/buildingAdd")
    @Transactional
    @ResponseBody
    public JsonResponse buildingAdd(@RequestBody Map<String, Object> params){
        Long ID = superAdminService.buildingAdd(params);
        if(ID == -1){
            return JsonResponse.failure("Building has already existed.");
        }
        Integer floor = (Integer) params.get("max_floor");
        List<Room> list = new ArrayList<>();
        for(int i=0;i<floor;i++){
            for(int j=0;j<roomNumPerFloor;j++){
                Room room = new Room();
                room

                        .setName(Long.toString(i*roomNumPerFloor+j))
                        .setModifyTime(LocalDateTime.now())
                        .setCreatedTime(LocalDateTime.now())
                        .setIsDeleted(0)
                        .setPosition(j)
                        .setBuilding(ID)
                        .setFloor(i + 1);
                list.add(room);
            }
        }
        boolean b = roomService.saveBatch(list);
        if(b)return JsonResponse.success(b, "Building add success.");
        else return JsonResponse.failure("The building has been existed.");
    }

    @PostMapping("/areaModify")
    @ResponseBody
    public JsonResponse areaModify(@RequestBody Area area){
        boolean b = areaService.areaModify(area);
        if(b)return JsonResponse.success(b, "Area add success.");
        else return JsonResponse.failure("The area has been deleted or not existed.");
    }
    @PostMapping("/buildingModify")
    @ResponseBody
    public JsonResponse buildingModify(@RequestBody Building building){
        boolean b = buildingService.buildingModify(building);
        if(b)return JsonResponse.success(b, "Building add success.");
        else return JsonResponse.failure("The building has been deleted or not existed.");
    }
    @DeleteMapping("/areaDelete")
    @Transactional
    @ResponseBody
    public JsonResponse areaDelete(String AreaID){
        LambdaQueryWrapper<Building> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Building::getArea, AreaID).eq(Building::getIsDeleted, 0);
        List<Building> list = buildingService.list(wrapper);
        for(Building building:list){
            this.buildingDelete(building.getId());
        }

        boolean b = areaService.removeById(Long.parseLong(AreaID));
        if(b)return JsonResponse.success(b, "Building delete success.");
        else return JsonResponse.failure("The building has been deleted or not existed.");
    }
    @PostMapping("/getTotalPeopleByAreaID")
    @ResponseBody
    public JsonResponse getTotalPeopleByAreaID(Long AreaID){
        int count = areaService.get_total_people_by_AreaID(AreaID);
        return JsonResponse.success(count);
    }


    @PostMapping("/selectBuildingByBuildingName")
    @ResponseBody
    public JsonResponse selectBuildingByBuildingName(@RequestBody Dot dot){
        List<Building> buildingList = buildingService.selectBuildByNamePage((String)dot.getData().get("buildingName"), dot);
        return JsonResponse.success(buildingList);
    }
    @DeleteMapping("/buildingDelete")
    @Transactional
    @ResponseBody
    public JsonResponse buildingDelete(Long BuildingID){
        QueryWrapper<Room> wrapper = new QueryWrapper<Room>();
        wrapper.eq("building", BuildingID);
        roomService.remove(wrapper);
        List<Room> rooms = roomService.list(wrapper);
        List<Long> idList = new ArrayList<>();
        rooms.forEach(r->{idList.add(r.getId());});
        roomService.removeByIds(idList);
        boolean b = buildingService.removeById(BuildingID);
        if(b)return JsonResponse.success(b, "Building delete success.");
        else return JsonResponse.failure("The building has been deleted or not existed.");
    }

    @PostMapping("/getTotalPeopleByBuildingID")
    @ResponseBody
    public JsonResponse getTotalPeopleByBuildingID(Long BuildingID){

        int count = buildingService.getTotelByBuildingID(BuildingID);
        return JsonResponse.success(count);
    }

    @PostMapping("/studentAll")
    @ResponseBody
    public JsonResponse studentAll(@RequestBody Dot dot){

        List<Student> students = studentService.selectPage(dot);
        return JsonResponse.success(students);
    }

    @PostMapping("/selectStudentByNameAndAccount")
    @ResponseBody
    public JsonResponse selectStudentByNameAndAccount(@RequestBody Dot dot){
        dot.setPageNo(dot.getPageSize()*(dot.getPageNo()-1));
        List<StudentForm> students = studentService.selectPageByNameAndAccount(dot);
        return JsonResponse.success(students);
    }

    @PostMapping("/selectLeaderByNameAndAccount")
    @ResponseBody
    public JsonResponse selectLeaderByNameAndAccount(@RequestBody Dot dot){
        dot.setPageNo(dot.getPageSize()*(dot.getPageNo()-1));
        List<Leader> leaders = leaderService.selectLeaderByNameAndAccount(dot);
        return JsonResponse.success(leaders);
    }

    @PostMapping("/selectKeeperByNameAndAccount")
    @ResponseBody
    public JsonResponse selectKeeperByNameAndAccount(@RequestBody Dot dot){

        List<Keeper> leaders = keeperService.selectKeeperByNameAndAccount(dot);
        return JsonResponse.success(leaders);
    }

    @PostMapping("/selectTeacherByNameAndAccount")
    @ResponseBody
    public JsonResponse selectTeacherByNameAndAccount(@RequestBody Dot dot){
        dot.setPageNo(dot.getPageSize()*(dot.getPageNo()-1));
        List<Teacher> teachers = teacherService.selectTeacherByNameAndAccount(dot);
        return JsonResponse.success(teachers);
    }
    @PostMapping("/selectDormitoryAdminByNameAndAccount")
    @ResponseBody
    public JsonResponse selectDormitoryAdminByNameAndAccount(@RequestBody Dot dot){
        dot.setPageNo(dot.getPageSize()*(dot.getPageNo()-1));
        List<DormitoryAdminForm> teachers = dormitoryAdminService.selectDormitoryAdminByNameAndAccount(dot);
        return JsonResponse.success(teachers);
    }
    @PostMapping("/dormitoryAdminAll")
    @ResponseBody
    public JsonResponse dormitoryAdminAll(@RequestBody Dot dot){
        dot.setPageNo(dot.getPageSize()*(dot.getPageNo()-1));
        List<DormitoryAdminForm> dormitoryAdminForms = dormitoryAdminService.dormitoryAdminAll(dot);
        int count = dormitoryAdminService.count();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("size", count);
        return JsonResponse.success(dormitoryAdminForms).setOtherData(map);
    }

    @PostMapping("/leaderAll")
    @ResponseBody
    public JsonResponse leaderAll(@RequestBody Dot dot){
        Page<Leader> leaderPage = new Page<Leader>(dot.getPageNo(), dot.getPageSize());
        IPage<Leader> leaderIPage = leaderService.page(leaderPage, new QueryWrapper<Leader>());
        int count = leaderService.count();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("size", count);
        return JsonResponse.success(leaderIPage.getRecords()).setOtherData(map);
    }
    @PostMapping("/keeperAll")
    @ResponseBody
    public JsonResponse keeperAll(@RequestBody Dot dot){

        Page<Keeper>  keeperPage= new Page<Keeper>(dot.getPageNo(), dot.getPageSize());
        IPage<Keeper> keeperIPage = keeperService.page(keeperPage, null);
        int count = keeperService.count();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("size", count);
        return JsonResponse.success(keeperIPage.getRecords()).setOtherData(map);
    }
    @PostMapping("/teacherAll")
    @ResponseBody
    public JsonResponse teacherAll(@RequestBody Dot dot){

        Page<Teacher>  teacherPage= new Page<Teacher>(dot.getPageNo(), dot.getPageSize());
        IPage<Teacher> teacherIPage = teacherService.page(teacherPage, null);
        int count = teacherService.count();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("size", count);
        return JsonResponse.success(teacherIPage.getRecords()).setOtherData(map);
    }

    @PostMapping("/modifyLeader")
    @ResponseBody
    public JsonResponse modifyLeader(@RequestBody Leader leader){
        leader.setModifiedTime(LocalDateTime.now());
        boolean b = leaderService.updateById(leader);
        if(b)return JsonResponse.success(b);
        return JsonResponse.failure("Fail to modify.");
    }
    @PostMapping("/modifyKeeper")
    @ResponseBody
    public JsonResponse modifyKeeper(@RequestBody Keeper keeper){
        keeper.setModifiedTime(LocalDateTime.now());
        boolean b = keeperService.updateById(keeper);
        return JsonResponse.success(b);
    }
    @PostMapping("/modifyStudent")
    @ResponseBody
    public JsonResponse modifyStudent(@RequestBody Student student){
        student.setModifiedTime(LocalDateTime.now());
        boolean b = studentService.updateById(student);
        return JsonResponse.success(b);
    }
    @PostMapping("/modifyDormitoryAdmin")
    @ResponseBody
    public JsonResponse modifyStudent(@RequestBody DormitoryAdmin dormitoryAdmin){
        dormitoryAdmin.setModifiedTime(LocalDateTime.now());
        boolean b = dormitoryAdminService.updateById(dormitoryAdmin);
        return JsonResponse.success(b);
    }
    @PostMapping("/addBatchStudent")
    @ResponseBody
    public JsonResponse addBatchStudent(@RequestBody List<Student> students){
        boolean b = true;
        List<String> accountList = new ArrayList<>();
        for(Student student:students){
            String account = student.getAccount();
            if(!(account!=null && !account.isEmpty() && account.charAt(0)=='s')){
                return JsonResponse.failure(String.format("\"%s\" is not a student account.", account));
            }
            student.setCreatedTime(LocalDateTime.now()).setModifiedTime(LocalDateTime.now());
            accountList.add(student.getAccount());
        }
        // 判断students内部是否有重复的account
        HashSet<String> set = new HashSet<>(accountList);
        boolean res = set.size() == accountList.size()? true:false;
        if(!res){
            return JsonResponse.failure("Account may repeated in your list.");
        }
        List<Student> students1 = studentService.listByAccounts(accountList);
        if(!students1.isEmpty()){
            return JsonResponse.failure("Account may existed");
        }
        b = studentService.saveBatch(students);
        return JsonResponse.success(b);
    }
    @PostMapping("/addStudent")
    @ResponseBody
    public JsonResponse addStudent(@RequestBody Student student){
        String account = student.getAccount();
        if(!(account!=null && !account.isEmpty() && account.charAt(0)=='s')){
            return JsonResponse.failure(String.format("\"%s\" is not a student account.", account));
        }
        QueryWrapper<Student> wrapper = new QueryWrapper<Student>().eq("account", account);
        List<Student> students = studentService.list(wrapper);
        if(!students.isEmpty()){
            return JsonResponse.failure("Account may existed.");
        }
        student.setCreatedTime(LocalDateTime.now()).setModifiedTime(LocalDateTime.now());
        boolean b = studentService.save(student);
        if(b)return JsonResponse.success(b);
        return JsonResponse.failure("ID may existed.");
    }

    @PostMapping("/addBatchTeacher")
    @ResponseBody
    public JsonResponse addBatchTeacher(@RequestBody List<Teacher> teachers){
        boolean b = true;
        List<String> idList = new ArrayList<>();
        for(Teacher teacher:teachers){
            String account = teacher.getAccount();
            if(!(account!=null && !account.isEmpty() && account.charAt(0)=='t')){
                return JsonResponse.failure(String.format("\"%s\" is not a teacher account.", account));
            }
            teacher.setCreatedTime(LocalDateTime.now()).setModifiedTime(LocalDateTime.now());
            idList.add(account);
        }
        // 判断是否有重复的account
        List<Teacher> teacherList = teacherService.listByAccount(idList);
        if(!teacherList.isEmpty()){
            return JsonResponse.failure("Account may existed.");
        }
        // 判断teachers内部是否有重复元素
        HashSet<String> set = new HashSet<>(idList);
        boolean res = set.size() == idList.size()? true:false;
        if(!res){
            return JsonResponse.failure("Account may repeated in your list.");
        }
        // 插入
        b = teacherService.saveBatch(teachers);
        if(b)return JsonResponse.success(b);
        return JsonResponse.failure("Account may existed.");
    }
    @PostMapping("/addTeacher")
    @ResponseBody
    public JsonResponse addTeacher(@RequestBody Teacher teacher){
        String account = teacher.getAccount();
        if(!(account!=null && !account.isEmpty() && account.charAt(0)=='t')){
            return JsonResponse.failure(String.format("\"%s\" is not a teacher account.", account));
        }
        QueryWrapper<Teacher> wrapper = new QueryWrapper<Teacher>().eq("account", account);
        List<Teacher> teachers = teacherService.list(wrapper);
        if(!teachers.isEmpty()){
            return JsonResponse.failure("Account may existed.");
        }
        teacher.setCreatedTime(LocalDateTime.now()).setModifiedTime(LocalDateTime.now());
        boolean b = teacherService.save(teacher);
        if(b)return JsonResponse.success(b);
        return JsonResponse.failure("Account may existed.");
    }
    @PostMapping("/addKeeper")
    @ResponseBody
    public JsonResponse addKeeper(@RequestBody Keeper keeper){
        String account = keeper.getAccount();
        if(!(account!=null && !account.isEmpty() && account.charAt(0)=='k')){
            return JsonResponse.failure(String.format("\"%s\" is not a keeper account.", account));
        }
        QueryWrapper<Keeper> wrapper = new QueryWrapper<Keeper>().eq("account", account);
        List<Keeper> keepers = keeperService.list(wrapper);
        if(!keepers.isEmpty()){
            return JsonResponse.failure("Account may existed.");
        }
        keeper.setCreatedTime(LocalDateTime.now()).setModifiedTime(LocalDateTime.now());
        boolean b = keeperService.save(keeper);
        if(b)return JsonResponse.success(b);
        return JsonResponse.failure("Account may existed.");
    }
    @PostMapping("/addLeader")
    @ResponseBody
    public JsonResponse addLeader(@RequestBody Leader leader){
        String account = leader.getAccount();
        if(!(account!=null && !account.isEmpty() && account.charAt(0)=='l')){
            return JsonResponse.failure(String.format("\"%s\" is not a leader account.", account));
        }
        QueryWrapper<Leader> wrapper = new QueryWrapper<Leader>().eq("account", account);
        List<Leader> leaders = leaderService.list(wrapper);
        if(!leaders.isEmpty()){
            return JsonResponse.failure("Account may existed.");
        }
        leader.setCreatedTime(LocalDateTime.now()).setModifiedTime(LocalDateTime.now());
        boolean b = leaderService.save(leader);
        if(b)return JsonResponse.success(b);
        return JsonResponse.failure("Account may existed.");
    }

    @PostMapping("/addDormitoryAdmin")
    @ResponseBody
    public JsonResponse addDormitoryAdmin(@RequestBody DormitoryAdmin dormitoryAdmin){
        String account = dormitoryAdmin.getAccount();
        if(!(account!=null && !account.isEmpty() && account.charAt(0)=='d')){
            return JsonResponse.failure(String.format("\"%s\" is not a dormitoryAdmin account.", account));
        }
        QueryWrapper<DormitoryAdmin> wrapper = new QueryWrapper<DormitoryAdmin>().eq("account", account);
        List<DormitoryAdmin> dormitoryAdmins = dormitoryAdminService.list(wrapper);
        if(!dormitoryAdmins.isEmpty()){
            return JsonResponse.failure("Account may existed.");
        }
        dormitoryAdmin.setCreatedTime(LocalDateTime.now()).setModifiedTime(LocalDateTime.now());
        boolean b = dormitoryAdminService.save(dormitoryAdmin);
        if(b)return JsonResponse.success(b);
        return JsonResponse.failure("Account may existed.");
    }
    @PostMapping("/searchRoomByAreaNameAndBuildingNameAndRoomName")
    @ResponseBody
    public JsonResponse searchRoomByAreaNameAndBuildingNameAndRoomName(@RequestBody Dot dot){
        assert (dot.getPageNo()>0);
        assert (dot.getPageSize()>0);
        dot.setPageNo((dot.getPageNo()-1)*dot.getPageSize());
        List<Map<String, Object>> res = roomService.searchRoomByAreaNameAndBuildingNameAndRoomName(dot);

        return JsonResponse.success(res);
    }

    @PostMapping("/getTotalPeopleByRoomID")
    @ResponseBody
    public JsonResponse getTotalPeopleByRoomID(Long RoomID){
        int count = studentService.count(new QueryWrapper<Student>().eq("room",RoomID));
        return JsonResponse.success(count);
    }
    @PostMapping("/selectRoomByBuildingIDAndFloor")
    @ResponseBody
    public JsonResponse selectRoomByBuildingIDAndFloor(Long buildingID, int floor){
        QueryWrapper<Room> wrapper = new QueryWrapper<Room>().eq("building", buildingID).eq("floor", floor);
        List<Room> list = roomService.list(wrapper);
        return JsonResponse.success(list);
    }

    @PostMapping("/modifyPositionOfRoomsInOneFloor")
    @ResponseBody
    public JsonResponse modifyPositionOfRoomsInOneFloor(@RequestBody List<Room> rooms){
        boolean b = roomService.updateBatchById(rooms);
        if(b)return JsonResponse.success("Success");
        else return JsonResponse.failure("Rooms may not exist.");
    }
    @PostMapping("/selectAreaByAreaID")
    @ResponseBody
    public JsonResponse selectAreaByAreaID(Long AreaID){

        Area area = areaService.getById(AreaID);

        if(area!=null)return JsonResponse.success(area);
        else return JsonResponse.failure("ID may not exist.");
    }

    @PostMapping("/allocateRoomsInManyFloors")
    @Transactional
    @ResponseBody
    public JsonResponse allocateRoomsInManyFloors(Integer startFloor,Integer endFloor,long BuildingID){
        Building building = buildingService.getOne(new QueryWrapper<Building>().eq("ID", BuildingID));
        QueryWrapper<Room> queryWrapper = new QueryWrapper<Room>()
                .eq("building", BuildingID)
                .between("floor" ,startFloor, endFloor);
        List<Room> list = roomService.list(queryWrapper);
        for(int i=(startFloor-1)*roomNumPerFloor;i<(min(endFloor, building.getMaxFloor()))*roomNumPerFloor;i++){
            list.get(i-(startFloor-1)*roomNumPerFloor)
                    .setModifyTime(LocalDateTime.now())
                    .setPosition(i%roomNumPerFloor);
        }
        boolean b = roomService.updateBatchById(list);
        if(b)return JsonResponse.success(b, "update success.");
        return JsonResponse.failure("update false.");
    }
    @PostMapping("/selectAreasByBuildingIDs")
    @Transactional
    @ResponseBody
    public JsonResponse selectAreasByBuildingIDs(@RequestBody List<Long> ids){
        List<Area> list = areaService.selectAreaByBuildingIDs(ids);
        if(list.size()!=ids.size())return JsonResponse.failure("Some id may not existed.");
        return JsonResponse.success(list);
    }
    @PostMapping("/selectBuildingsByDormitoryAdminIDs")
    @Transactional
    @ResponseBody
    public JsonResponse selectBuildingsByDormitoryAdminIDs(@RequestBody List<Long> ids){
        List<Building> list = buildingService.selectBuildingsByDormitoryAdminIDs(ids);
        if(list.size()!=ids.size())return JsonResponse.failure("Some id may not existed.");
        return JsonResponse.success(list);
    }

    @PostMapping("/selectBuildingWithAreaNameByBuildingName")
    @ResponseBody
    public JsonResponse selectBuildingWithAreaNameByBuildingName(@RequestBody Dot dot){
        dot.setPageNo((dot.getPageNo()-1)*dot.getPageSize());
        List<Map<String, Object>> list = buildingService.selectBuildingWithAreaNameByBuildingName(dot);
        return JsonResponse.success(list);
    }

}

